package com.huawei.appmarket.framework.widget;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.huawei.appgallery.forum.posts.api.PostProfiles;
import com.huawei.appgallery.foundation.ui.css.CSSRule;
import com.huawei.appgallery.foundation.ui.css.CSSViewProxy;
import com.huawei.appgallery.foundation.ui.css.RenderListener;
import com.huawei.appgallery.foundation.ui.css.adapter.CSSPropertyName;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSMonoColor;
import com.huawei.secure.android.common.intent.SafeIntent;
import o.azb;
import o.bzh;
import o.bzj;
import o.dje;
import o.djt;
import o.Logger;
import o.ContentManager;
import o.dsb;
import o.dzn;
import o.epo;
import o.epv;
import o.epw;
import o.erq;
import o.evd;
import o.evx;
import o.ewm.c;
import o.ewm.e;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;
import o.fho;
import o.ll;

public class CustomActionBar extends LinearLayout implements RenderListener, b {
    private RelativeLayout ʻ;
    private Drawable ʻॱ;
    private int ʼ;
    private Drawable ʼॱ;
    private int ʽ;
    private Drawable ʽॱ;
    private Drawable ʾ;
    private Drawable ʿ;
    private int ˈ;
    private djt ˉ;
    protected String ˊ;
    private int ˊˊ;
    private d ˊˋ;
    private boolean ˊॱ;
    private int ˊᐝ;
    private RelativeLayout ˋ;
    private int ˋˊ;
    private RelativeLayout ˋˋ;
    private CssImageView ˋॱ;
    private Drawable ˋᐝ;
    private Drawable ˌ;
    private LinearLayout ˍ;
    private View ˎ;
    private CssImageView ˎˎ;
    private dje ˎˏ;
    protected String ˏ;
    private dsb ˏˎ;
    private boolean ˏˏ;
    private boolean ˏॱ;
    private int ˑ;
    private int ͺ;
    private boolean ͺॱ;
    private View ॱ;
    private ImageView ॱˊ;
    private ImageView ॱˋ;
    private Drawable ॱˎ;
    private RelativeLayout ॱॱ;
    private int ॱᐝ;
    private TextView ᐝ;
    private int ᐝॱ;

    class d extends BroadcastReceiver {
        final /* synthetic */ CustomActionBar ˎ;

        private d(CustomActionBar customActionBar) {
            this.ˎ = customActionBar;
        }

        public void onReceive(Context context, Intent intent) {
            SafeIntent safeIntent = new SafeIntent(intent);
            if (this.ˎ.getVisibility() == 0) {
                int hashCode;
                if (this.ˎ.getContext() != null) {
                    hashCode = this.ˎ.getContext().hashCode();
                } else {
                    hashCode = -1;
                }
                int intExtra = safeIntent.getIntExtra("main_image_color", 0);
                int intExtra2 = safeIntent.getIntExtra("main_image_height", -1);
                if (safeIntent.getIntExtra("activity_hash_code", -1) == hashCode) {
                    this.ˎ.setImageHeight(intExtra2);
                    this.ˎ.setImageMainColor(intExtra);
                }
            }
        }
    }

    public CustomActionBar(Context context) {
        this(context, null);
    }

    public CustomActionBar(Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public CustomActionBar(Context context, @Nullable AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ʽ = -1;
        this.ʼ = -1;
        this.ˊॱ = false;
        this.ˏॱ = false;
        this.ͺ = 0;
        this.ᐝॱ = 0;
        this.ॱᐝ = -1;
        this.ˈ = -1;
        this.ˊˊ = -1;
        this.ˋˊ = 1001;
        this.ˊᐝ = 0;
        this.ˏˏ = false;
        ˏ(context);
        this.ʽ = context.getResources().getColor(c.ॱˎ);
    }

    public static void ˎ(Context context, int i, int i2) {
        Intent intent = new Intent();
        intent.setAction("com.huawei.appmarket.action.GetImageMainColor");
        intent.putExtra("main_image_color", i);
        intent.putExtra("main_image_height", i2);
        intent.putExtra("activity_hash_code", context.hashCode());
        ll.ˏ(context).ˋ(intent);
    }

    private void ˏ(Context context) {
        this.ॱ = View.inflate(context, h.ߺ, null).findViewById(j.ʾﾞ);
        azb.ˏ(this.ॱ);
        this.ˋ = (RelativeLayout) this.ॱ.findViewById(j.ʻⁱ);
        this.ʻ = (RelativeLayout) this.ॱ.findViewById(j.ʼʻ);
        this.ॱॱ = (RelativeLayout) this.ॱ.findViewById(j.ʽי);
        this.ˍ = (LinearLayout) this.ॱ.findViewById(j.ॱₗ);
        this.ˋˋ = (RelativeLayout) this.ॱ.findViewById(j.ʽʽ);
        this.ˎ = this.ॱ.findViewById(j.ʽⁱ);
        this.ˎ.setLayoutParams(new LayoutParams(-1, epv.ॱ()));
        this.ˎ.setVisibility(0);
        OnClickListener cVar = new c(this, null);
        this.ˋ.setOnClickListener(cVar);
        this.ʻ.setOnClickListener(cVar);
        this.ॱॱ.setOnClickListener(cVar);
        this.ᐝ = (TextView) this.ॱ.findViewById(j.ˈʿ);
        this.ˋॱ = (CssImageView) this.ॱ.findViewById(j.ʻﹶ);
        this.ॱˊ = (ImageView) this.ॱ.findViewById(j.ʽʹ);
        this.ॱˋ = (ImageView) this.ॱ.findViewById(j.ʼʼ);
        this.ˎˎ = (CssImageView) this.ॱ.findViewById(j.ʾˋ);
        this.ˋॱ.setCssImageListener(this);
        addView(this.ॱ, new LayoutParams(-1, -2));
        this.ʿ = context.getResources().getDrawable(e.ˋʼ);
        this.ʾ = context.getResources().getDrawable(e.ʻˊ);
        this.ʽॱ = context.getResources().getDrawable(e.ˊˋ);
        this.ˌ = context.getResources().getDrawable(e.ˊˊ);
        this.ॱˎ = epo.ॱ(this.ʿ, -1);
        this.ʻॱ = epo.ॱ(this.ʾ, -1);
        this.ʼॱ = epo.ॱ(this.ʽॱ, -1);
        this.ˋᐝ = epo.ॱ(this.ˌ, -1);
        this.ˋˊ = epw.ˊ();
    }

    public void setContentType(int i) {
        this.ॱᐝ = i;
    }

    public int ॱ() {
        if (this.ʼ > 0) {
            return this.ʼ;
        }
        this.ʼ = ContentManager.getInstant().getContext().getResources().getDimensionPixelSize(o.ewm.d.ʼᐝ) + epv.ॱ();
        return this.ʼ;
    }

    public void ˋ(boolean z) {
        this.ˊॱ = z;
    }

    public void setIsSecondaryList(boolean z) {
        this.ˏˏ = z;
        if (z && !this.ˏॱ && !epw.ˏ()) {
            setBackgroundColor(this.ʽ);
            this.ᐝ.setAlpha(1.0f);
        }
    }

    public void setImageMainColor(int i) {
        if (!this.ˏˏ || this.ͺ == 0) {
            this.ͺ = i;
            if (!this.ˊॱ) {
                Context ˋ = ContentManager.getInstant().getContext();
                this.ʿ = ˋ.getResources().getDrawable(e.ˋʼ);
                this.ʾ = ˋ.getResources().getDrawable(e.ʻˊ);
                this.ʽॱ = ˋ.getResources().getDrawable(e.ˊˋ);
                if (!azb.ˎ(ˋ) || this.ˏˏ) {
                    if (erq.ˏ(i) && !epw.ˏ()) {
                        this.ॱˎ = epo.ॱ(this.ʿ, -1);
                        this.ʻॱ = epo.ॱ(this.ʾ, -1);
                        this.ʼॱ = epo.ॱ(this.ʽॱ, -1);
                        this.ˋᐝ = epo.ॱ(this.ˌ, -1);
                        setBackgroundColor(0);
                        this.ᐝ.setAlpha(0.0f);
                        ˋ(-16777216);
                        this.ˋॱ.setBackground(this.ॱˎ);
                        this.ॱˊ.setBackground(this.ʻॱ);
                        this.ॱˋ.setBackground(this.ʼॱ);
                        this.ˎˎ.setBackground(this.ˋᐝ);
                        ˏ(-1);
                    }
                    if (!erq.ˏ(i) && epw.ˏ()) {
                        this.ॱˎ = epo.ॱ(this.ʿ, -16777216);
                        this.ʻॱ = epo.ॱ(this.ʾ, -16777216);
                        this.ʼॱ = epo.ॱ(this.ʽॱ, -16777216);
                        this.ˋᐝ = epo.ॱ(this.ˌ, -16777216);
                        setBackgroundColor(0);
                        this.ᐝ.setAlpha(0.0f);
                        ˋ(-1);
                        this.ˋॱ.setBackground(this.ॱˎ);
                        this.ॱˊ.setBackground(this.ʻॱ);
                        this.ॱˋ.setBackground(this.ʼॱ);
                        this.ˎˎ.setBackground(this.ˋᐝ);
                        ˏ(-16777216);
                    }
                    if (!erq.ˏ(i) && !epw.ˏ() && this.ˏˏ) {
                        this.ॱˎ = epo.ॱ(this.ʿ, -16777216);
                        this.ʻॱ = epo.ॱ(this.ʾ, -16777216);
                        this.ʼॱ = epo.ॱ(this.ʽॱ, -16777216);
                        this.ˋᐝ = epo.ॱ(this.ˌ, -16777216);
                        setBackgroundColor(0);
                        this.ᐝ.setAlpha(0.0f);
                        ˋ(-1);
                        this.ˋॱ.setBackground(this.ॱˎ);
                        this.ॱˊ.setBackground(this.ʻॱ);
                        this.ॱˋ.setBackground(this.ʼॱ);
                        this.ˎˎ.setBackground(this.ˋᐝ);
                        ˏ(-16777216);
                    }
                }
            }
        }
    }

    public void setImageHeight(int i) {
        this.ˈ = i;
    }

    public void ˋ() {
        Context ˋ = ContentManager.getInstant().getContext();
        if (epw.ˊ() != this.ˋˊ) {
            this.ˋˊ = epw.ˊ();
            ˎ(ˋ);
            setBackgroundColor(0);
            setImageMainColor(this.ͺ);
            int i = this.ˊᐝ;
            this.ˊᐝ = 10000;
            ˋ(i, this.ˊˊ);
        }
    }

    public void ˋ(int i, int i2) {
        Context ˋ = ContentManager.getInstant().getContext();
        ˎ(ˋ);
        this.ˊˊ = i2;
        if (this.ˈ > 0 && i2 > 0) {
            i2 = this.ˈ;
        }
        if (ॱ(ˋ)) {
            ˋ(i, i2, false);
            return;
        }
        int ˋ2 = (i2 - epv.ˋ(getContext(), 64)) - ॱ();
        int ˋ3 = (i2 - epv.ˋ(getContext(), 48)) - ॱ();
        int ˋ4 = epv.ˋ(getContext(), 16);
        int color = ˋ.getResources().getColor(c.ʼ);
        int color2 = ˋ.getResources().getColor(c.ॱˎ);
        this.ॱˎ = epo.ॱ(this.ʿ, color2);
        this.ʻॱ = epo.ॱ(this.ʾ, color2);
        this.ʼॱ = epo.ॱ(this.ʽॱ, color2);
        this.ˋᐝ = epo.ॱ(this.ˌ, color2);
        if (i <= ˋ2) {
            setBackgroundColor(0);
            this.ᐝ.setAlpha(0.0f);
            if (this.ˊᐝ <= ˋ2) {
                this.ˊᐝ = i;
                return;
            }
            this.ˊᐝ = i;
            ˋ(color);
            this.ˋॱ.setBackground(this.ॱˎ);
            this.ॱˊ.setBackground(this.ʻॱ);
            this.ॱˋ.setBackground(this.ʼॱ);
            this.ˎˎ.setBackground(this.ˋᐝ);
            ˏ(color2);
        } else if (i <= ˋ2 || i >= ˋ3) {
            ˋ2 = (i2 - epv.ˋ(getContext(), 32)) - ॱ();
            if (i < ˋ3 || i > ˋ2) {
                this.ˊᐝ = i;
                ˋ(color2);
                ˋ(i, i2, true);
                return;
            }
            setBackgroundColor(0);
            this.ᐝ.setAlpha(0.0f);
            if (this.ˊᐝ < ˋ3 || this.ˊᐝ > ˋ2) {
                this.ˊᐝ = i;
                ˋ(color);
                this.ˋॱ.setBackgroundColor(0);
                this.ॱˊ.setBackgroundColor(0);
                this.ॱˋ.setBackgroundColor(0);
                this.ˎˎ.setBackgroundColor(0);
                ˏ(0);
                return;
            }
            this.ˊᐝ = i;
        } else {
            setBackgroundColor(0);
            this.ᐝ.setAlpha(0.0f);
            this.ˊᐝ = i;
            color2 = erq.ˊ(color2, 1.0f - ˎ(i - ˋ2, ˋ4));
            this.ˋॱ.setBackground(epo.ॱ(this.ॱˎ, color2));
            this.ॱˊ.setBackground(epo.ॱ(this.ʻॱ, color2));
            this.ॱˋ.setBackground(epo.ॱ(this.ʼॱ, color2));
            this.ˎˎ.setBackground(epo.ॱ(this.ˋᐝ, color2));
            ˏ(color2);
        }
    }

    private boolean ॱ(Context context) {
        return !(erq.ˏ(this.ͺ) || epw.ˏ()) || this.ˊॱ || ((erq.ˏ(this.ͺ) && epw.ˏ()) || this.ͺ == 0 || (azb.ˎ(context) && !this.ˏˏ));
    }

    private void ˎ(Context context) {
        if (!this.ˊॱ && !this.ˏॱ) {
            if (this.ॱᐝ == 1000) {
                this.ʽ = context.getResources().getColor(c.ॱˎ);
            }
            if (this.ॱᐝ == 1001) {
                this.ʽ = context.getResources().getColor(c.ॱˎ);
            }
        }
    }

    private void ˋ(int i, int i2, boolean z) {
        float f;
        int color = ContentManager.getInstant().getContext().getResources().getColor(c.ʼ);
        int ˋ = epv.ˋ(getContext(), 32);
        int ॱ = (i2 - ˋ) - ॱ();
        if (ॱ <= 0) {
            f = 1.0f;
            setBackgroundColor(this.ʽ);
        } else if (i > ॱ) {
            f = ˎ(i - ॱ, ˋ);
            setBackgroundColor(erq.ˊ(this.ʽ, f));
        } else {
            f = 0.0f;
            setBackgroundColor(0);
        }
        this.ᐝ.setAlpha(f);
        if (z) {
            ˋ = erq.ˊ(color, f);
            this.ˋॱ.setBackground(epo.ॱ(this.ʿ, ˋ));
            this.ॱˊ.setBackground(epo.ॱ(this.ʾ, ˋ));
            this.ॱˋ.setBackground(epo.ॱ(this.ʽॱ, ˋ));
            this.ˎˎ.setBackground(epo.ॱ(this.ˌ, ˋ));
            ˏ(ˋ);
        }
    }

    private float ˎ(int i, int i2) {
        if (i2 <= 0) {
            return 1.0f;
        }
        float f = (1.0f / ((float) i2)) * ((float) i);
        if (f <= 1.0f) {
            return f;
        }
        return 1.0f;
    }

    public void setBgColor(int i) {
        this.ʽ = i;
    }

    public void setImmerStyle(boolean z) {
        this.ˏॱ = z;
    }

    public void setTitle(CharSequence charSequence) {
        if (this.ᐝ != null) {
            this.ᐝ.setText(charSequence);
        }
    }

    public void setActionbarClickListener(djt o_djt) {
        this.ˉ = o_djt;
    }

    public boolean onRenderReady(CSSViewProxy cSSViewProxy) {
        CSSRule rule = cSSViewProxy.getRule();
        if (rule.getStyleDeclaration() != null) {
            CSSMonoColor cSSMonoColor = (CSSMonoColor) rule.getStyleDeclaration().getPropertyValue(CSSPropertyName.BACKGROUND_COLOR);
            if (cSSMonoColor != null) {
                int color = cSSMonoColor.getColor();
                this.ˏॱ = true;
                setBgColor(color);
                Window window = ((Activity) getContext()).getWindow();
                window.setNavigationBarColor(color);
                if (erq.ˏ(color)) {
                    if (!evd.ˎ()) {
                        window.setStatusBarColor(-16777216);
                    } else if (VERSION.SDK_INT >= 26) {
                        evd.ˊ(window, 1);
                    }
                } else if (evd.ˎ()) {
                    evd.ˊ(window, 0);
                } else {
                    window.setStatusBarColor(-1);
                }
            }
        }
        return false;
    }

    private void ˋ(int i) {
        Window window = ((Activity) getContext()).getWindow();
        if (!evd.ˎ()) {
            window.setStatusBarColor(i);
        } else if (erq.ˏ(i)) {
            evd.ˏ(window, 1);
        } else {
            evd.ˏ(window, 0);
        }
    }

    public void setSearchIconVisible(int i) {
        if (this.ˋ != null) {
            this.ˋ.setVisibility(i);
        }
    }

    public void setShareIconVisible(int i) {
        if (this.ॱॱ != null) {
            this.ॱॱ.setVisibility(i);
        }
    }

    public void setCloseIconRes(int i) {
        if (this.ॱˋ != null) {
            this.ॱˋ.setBackgroundResource(i);
        }
    }

    public void ˏ() {
        this.ˊˋ = new d();
        ll.ˏ(ContentManager.getInstant().getContext()).ˏ(this.ˊˋ, new IntentFilter("com.huawei.appmarket.action.GetImageMainColor"));
    }

    public void ˎ() {
        try {
            if (this.ˊˋ != null) {
                ll.ˏ(ContentManager.getInstant().getContext()).ˋ(this.ˊˋ);
            }
        } catch (Exception e) {
            Logger.ˋ("CustomActionBar", "unregisterVideoReceiver error:" + e.toString());
        }
    }

    public void ॱ(String str, final boolean z, final boolean z2) {
        this.ˍ.setVisibility(8);
        this.ॱॱ.setVisibility(8);
        this.ˋ.setVisibility(8);
        this.ˋˋ.setVisibility(8);
        if (this.ˎˏ != null) {
            bzh ˊˊ = this.ˎˏ.ˊˊ();
            if (!(ˊˊ == null || ˊˊ.ˋ() == null)) {
                ˎ(ˊˊ);
                ˎ(true, z, z2);
                return;
            }
        }
        dzn.ॱ(str, new dzn.e(this) {
            final /* synthetic */ CustomActionBar ˎ;

            public void ˋ(PostProfiles postProfiles) {
                if (postProfiles != null) {
                    bzh o_bzh = new bzh();
                    o_bzh.ˎ(postProfiles);
                    o_bzh.ˋ(this.ˎ.ˏ);
                    o_bzh.ˎ(this.ˎ.ˊ);
                    if (this.ˎ.ˎˏ != null) {
                        this.ˎ.ˎˏ.ˋ(o_bzh);
                    }
                    this.ˎ.ˎ(o_bzh);
                }
                this.ˎ.ˎ(postProfiles != null, z, z2);
            }
        });
    }

    private void ˎ(bzh o_bzh) {
        this.ˍ.removeAllViews();
        this.ˍ.setVisibility(0);
        this.ˏˎ = ((bzj) fho.ˏ().ˋ("Posts").ॱ(bzj.class)).ॱ(this.ˍ, o_bzh);
        if (this.ͺॱ) {
            this.ˏˎ.ˊ(this.ˑ);
        }
    }

    private void ˎ(boolean z, boolean z2, boolean z3) {
        int i = 0;
        RelativeLayout relativeLayout;
        int i2;
        RelativeLayout relativeLayout2;
        if (!z) {
            this.ˍ.setVisibility(8);
            relativeLayout = this.ॱॱ;
            if (z2) {
                i2 = 0;
            } else {
                i2 = 8;
            }
            relativeLayout.setVisibility(i2);
            relativeLayout2 = this.ˋ;
            if (!z3) {
                i = 8;
            }
            relativeLayout2.setVisibility(i);
            this.ˋˋ.setVisibility(8);
        } else if (z2 && z3) {
            this.ॱॱ.setVisibility(8);
            this.ˋ.setVisibility(8);
            this.ˋˋ.setVisibility(0);
            this.ˋˋ.setOnClickListener(new evx(this) {
                final /* synthetic */ CustomActionBar ˊ;

                {
                    this.ˊ = r1;
                }

                public void ˋ(View view) {
                    this.ˊ.ˊ();
                }
            });
        } else {
            relativeLayout = this.ॱॱ;
            if (z2) {
                i2 = 0;
            } else {
                i2 = 8;
            }
            relativeLayout.setVisibility(i2);
            relativeLayout2 = this.ˋ;
            if (!z3) {
                i = 8;
            }
            relativeLayout2.setVisibility(i);
            this.ˋˋ.setVisibility(8);
        }
    }

    public void setForumDataListener(dje o_dje) {
        this.ˎˏ = o_dje;
    }

    private void ˊ() {
        PopupMenu popupMenu = new PopupMenu(getContext(), this.ˋˋ);
        popupMenu.getMenu().add(getContext().getResources().getString(n.ʳ)).setOnMenuItemClickListener(new OnMenuItemClickListener(this) {
            final /* synthetic */ CustomActionBar ˋ;

            {
                this.ˋ = r1;
            }

            public boolean onMenuItemClick(MenuItem menuItem) {
                if (this.ˋ.ˉ != null) {
                    this.ˋ.ˉ.ˊˋ();
                }
                return true;
            }
        });
        popupMenu.getMenu().add(getContext().getResources().getString(n.ˋי)).setOnMenuItemClickListener(new OnMenuItemClickListener(this) {
            final /* synthetic */ CustomActionBar ˊ;

            {
                this.ˊ = r1;
            }

            public boolean onMenuItemClick(MenuItem menuItem) {
                if (this.ˊ.ˉ != null) {
                    this.ˊ.ˉ.ʼॱ();
                }
                return true;
            }
        });
        popupMenu.show();
    }

    public void setCss(String str) {
        this.ˏ = str;
    }

    public void setCssSelector(String str) {
        this.ˊ = str;
    }

    private void ˏ(int i) {
        this.ͺॱ = true;
        this.ˑ = i;
        if (this.ˏˎ != null) {
            this.ˏˎ.ˊ(i);
        }
    }
}
